//排序
let gg = document.querySelectorAll('.gg');
let hh = document.querySelectorAll('.hh');
function sortTable(order) {
    let flag = true;
    for (let i = 1; i < gg.length; ++i) {
        if (flag) flag = false;
        else break;
        for (let j = 0; j < gg.length - i; ++j) {
            if (order) {
                if (gg[j].innerHTML > gg[j + 1].innerHTML) {
                    let temp = gg[j].innerHTML;
                    gg[j].innerHTML = gg[j + 1].innerHTML;
                    gg[j + 1].innerHTML = temp;

                    temp = hh[j].innerHTML;
                    hh[j].innerHTML = hh[j + 1].innerHTML;
                    hh[j + 1].innerHTML = temp;
                    flag = true;
                }
            } else {
                if (gg[j].innerHTML < gg[j + 1].innerHTML) {
                    let temp = gg[j].innerHTML;
                    gg[j].innerHTML = gg[j + 1].innerHTML;
                    gg[j + 1].innerHTML = temp;

                    temp = hh[j].innerHTML;
                    hh[j].innerHTML = hh[j + 1].innerHTML;
                    hh[j + 1].innerHTML = temp;
                    flag = true;
                }
            }
        }
    }
}
let order = true;
let header = document.querySelector(".header");
header.addEventListener("click", () => { sortTable(order); order = !order; });



// 查找
function search() {
    let input = document.getElementById("myInput");
    let filter = input.value.toUpperCase();
    let table = document.getElementById("myTable");
    let tr = table.querySelectorAll("tr");
    // 循环表格每一行，查找匹配项
    for (let i = 0; i < tr.length; i++) {
        let td = tr[i].querySelectorAll("td")[0]; //获得第一列（公司名称）
        if (td) {
            if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
}
let input = document.getElementById("myInput");
input.addEventListener("input", search);